package com.io;

import org.junit.Test;

import java.io.*;

/**
 * 测试InputStream
 * Created by yangliwei on 2017/7/19.
 */
public class InputStreamDemo {

    /**
     * 测试read方法
     */
    @Test
    public void testRead() throws FileNotFoundException {
        byte[] b = new byte[20];//数字初始化的值为0，全部都是0，
        for (int i = 0; i < 20; i++) {
            b[i] = (byte) i;
        }
        InputStream in = new ByteArrayInputStream(b);
        in = new FileInputStream("/home/away/IdeaProjects/javastudy/src/com/io/FileDemo.java");
        byte[] result = new byte[1024];
        int temp;
        try {
            temp = in.read(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws FileNotFoundException {
        byte[] b = new byte[20];//数字初始化的值为0，全部都是0，
        for (int i = 0; i < 20; i++) {
            b[i] = (byte) i;
        }
        InputStream in = new ByteArrayInputStream(b);
        in = new FileInputStream("/home/away/IdeaProjects/javastudy/src/com/io/FileDemo.java");
        byte[] result = new byte[8];
        int temp;
        try {
            while ((temp = in.read(result)) != -1){
                System.out.println(temp);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
